package interceptor.config;

import interceptor.interceptor.LoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author quan
 * @Description TODO
 * @Date 2023/7/28 17:27
 */
//实现WebMvcConfigurer
//@Configuration
public class AppConfig implements WebMvcConfigurer {
    //方式2：通过注解的方式
    @Autowired
    private LoginInterceptor loginInterceptor;
    //重写addInterceptors方法
    @Override
    public void addInterceptors(InterceptorRegistry registry){
        //添加拦截器
        //先要有一个拦截器对象:方式1：直接new出来
//        LoginInterceptor loginInterceptor = new LoginInterceptor();
        registry.addInterceptor(loginInterceptor)
                .addPathPatterns("/**")//表示拦截所有
                .excludePathPatterns("/api/aop/loginBlog1")//表示排除掉一些方法
                .excludePathPatterns("/api/aop/regBlog1");//表示排除掉一些方法
    }
    //url统一加前缀api访问
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.addPathPrefix("api", c -> true);
    }
}
